package com.test.controller;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.test.R;

/**
 * 吐司提示设置
 *
 * @Author Musique
 * 2020/8/7
 */
public class ToastActivity extends AppCompatActivity {

    private Context mContext;

    int onClick = 0;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.toast_demo);
        mContext = this;
        // final修饰的文本不可再变
        final Toast toast = Toast.makeText(mContext, "点击按钮", Toast.LENGTH_LONG);

        // 布局弹出的位置
        toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
        //布局自定义toast的样式
        LinearLayout linearLayout = (LinearLayout) toast.getView();
        TextView textView = linearLayout.findViewById(android.R.id.message);
        textView.setTextColor(Color.parseColor("#FF83DA5E"));
        //        textView.setBackgroundColor(Color.parseColor("#CDDC39"));
        //        ImageView img = new ImageView(this);
        //        img.setBackgroundResource(R.mipmap.iv_icon_2);
        //        linearLayout.addView(img, 0);

        Button btn_demo = findViewById(R.id.btn_demo);
        btn_demo.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // 记录点击次数
                // onClick = onClick + 1;
                // Toast.makeText(mContext, "点击按钮" + onClick, Toast.LENGTH_LONG).show();
                toast.show();
            }
        });
    }
}
